home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Read It Later 0.9924 / read_it_later-0.9924-fx.xpi / chrome / isreaditlater.jar / content / ISRILgr.js < prev    next >
Text File  |  2008-10-28  |  6KB  |  123 lines

  1. function ISRILgr()
  2. {
  3.     this.empty = 'chrome://isreaditlater/skin/markempty16.png';
  4.     this.full = 'chrome://isreaditlater/skin/markfull16.png';
  5.     this.TO = null;
  6. }
  7.  
  8. ISRILgr.prototype = {
  9.         
  10.         _init : function() {
  11.                         
  12.         },
  13.         
  14.         _initpage : function() {
  15.             if (content.document.getElementById('entries')) {
  16.                 content.document.getElementById('entries').addEventListener('DOMNodeInserted', ISRILgr.readyUpdate, true);
  17.             }
  18.             ISRILxul.bi("appcontent").removeEventListener("DOMContentLoaded", this._initpage, false);
  19.         },
  20.         
  21.         check : function() {
  22.             if (ISRILprefs.prefB('integrate-gr')) {
  23.                 var u = ISRIL.url();
  24.                 
  25.                 if (u.match('google') || u.match(/^https?:\/\/reader.google.(.+)/) || u.match(/^https?:\/\/([^.]+\.)?google.(.+)\/reader/)) {
  26.                     ISRILxul.bi("appcontent").addEventListener("DOMContentLoaded", this._initpage, true);   
  27.                 }                
  28.             }
  29.         },
  30.         
  31.         readyUpdate : function() {
  32.             clearInterval(ISRILgr.TO);
  33.             ISRILgr.TO = setTimeout('ISRILgr.updateEntries()', 50);
  34.         },
  35.         
  36.         updateEntries : function() {
  37.             var entries = this.getElementsByClassName(content.document, 'entry', null, 'ril-set');
  38.             if (entries.length > 0) {
  39.                 ISRIL.GetList();
  40.                 
  41.                 for(var i = 0; i<entries.length; i++) {
  42.                     
  43.                     if (!entries[i].className.match('ril-set')) {
  44.                         
  45.                         //Create Checkmark
  46.                         checkmark = content.document.createElement('img');
  47.                         
  48.                         //Determine View Type
  49.                         org = this.getElementsByClassName(entries[i], 'entry-original')[0];
  50.                         titleLink = this.getElementsByClassName(entries[i], 'entry-title-link')[0];
  51.                         
  52.                         if (org || titleLink) {
  53.                         
  54.                             if (org) {
  55.                                 
  56.                                 viewType = 'list';
  57.                                 
  58.                                 url = org.href;
  59.                                 pageTitle = this.getElementsByClassName(entries[i], 'entry-title')[0].innerHTML;
  60.                                 sec = this.getElementsByClassName(entries[i], 'entry-secondary')[0];
  61.                                 source = this.getElementsByClassName(entries[i], 'entry-source-title')[0];
  62.                                 ctn = content.document.getElementById('entries').className.match('single-source') ? sec : source;
  63.                                 
  64.                                 checkmark.style.marginRight = '9px';
  65.                                 
  66.                             } else if (titleLink) {
  67.  
  68.                                 viewType = 'expanded';
  69.                                 
  70.                                 url = titleLink.href;
  71.                                 pageTitle = titleLink.innerHTML.replace(/<([^>]+)>/, '').replace(/(^\s+|\s+$)/, '') + '';
  72.                                 ctn = this.getElementsByClassName(entries[i], 'entry-icons')[0];                               
  73.                                 
  74.                             }
  75.                         
  76.                             //Set Checkmark attributes                       
  77.                             checkmark.src = ISRILglobals.ResolverIndex[url] ? this.full : this.empty;
  78.                             checkmark.width = 15;
  79.                             checkmark.height = 15;
  80.                             checkmark.style.cursor = 'pointer';
  81.                             
  82.                             //Get Info and Nodes
  83.                             checkmark.setAttribute('url', url);
  84.                             checkmark.setAttribute('pageTitle', pageTitle);
  85.                             checkmark.addEventListener("click", this.clickMark, true);
  86.                             
  87.                             //Add Checkmark
  88.                             ctn.insertBefore( checkmark , ctn.firstChild );
  89.                         }
  90.                             
  91.                         entries[i].className += ' ril-set';
  92.                     }
  93.                 }
  94.             }
  95.         },
  96.         
  97.         clickMark : function(e) {
  98.             e.stopPropagation();
  99.             if (this.src == ISRILgr.full) {
  100.                 ISRIL.MarkAsRead( ISRILglobals.ResolverIndex[ this.getAttribute('url') ].itemId, true );                
  101.                 this.src = ISRILgr.empty;                
  102.             } else {
  103.                 ISRIL.SaveLink( this.getAttribute('url') , this.getAttribute('pageTitle') );
  104.                 this.src = ISRILgr.full;
  105.             }
  106.         },
  107.         
  108.         // -- //
  109.         
  110.         getElementsByClassName  : function (parent, className, nodeName, notClassName) {
  111.             var result = [], tag = nodeName||'*', node, seek, i;
  112.             var rightClass = new RegExp( '(^| )'+ className +'( |$)' );
  113.             var wrongClass = new RegExp( '(^| )'+ notClassName +'( |$)' );
  114.             seek = parent.getElementsByTagName( tag );
  115.             for( i=0; i<seek.length; i++ )
  116.               if( rightClass.test( (node = seek[i]).className ) && !wrongClass.test( (node = seek[i]).className ) )
  117.                 result.push( seek[i] );
  118.             return result;
  119.         },      
  120.         
  121. }
  122.  
  123. ISRILgr = new ISRILgr();